
import {
	plankEquipments,
	reagentEquipments,
	equipmentTwos,
	equipmentThrees,
	threeEquipmentTwos
} from '@/common/default'

class step {
	constructor(arg) {
	}
	changeStep(res) {
		return new Promise((resolve,reject)=>{
			let arr = [{
				title: '制备核酸提取液和扩增体系',
				man: res.one ? res.one.reagentThree : '',
				time: res.one ? res.timeOne : '',
				xiaohao: [{
					title: '预装版',
					detail: res.one ? res.one.plank : '',
				}, {
					title: '预装版数量',
					detail: res.one ? res.one.plankBatch : '',
				}, {
					title: 'PCR检测试剂',
					detail: res.one ? res.one.reagent : '',
				}, {
					title: '检测试剂数量',
					detail: res.one ? res.one.reagentBatch : '',
				}, {
					title: '枪头',
					detail: res.one ? res.one.gun : '',
				}],
				type: res.type,
				status: res.one ? res.one.nameTow ? statusChange(plankEquipments, res.one.plankEquipment || []) : 2 : 2,
				equipment: res.one ? Compare(plankEquipments, res.one.plankEquipment || []) : [],
				index: 0
			},
			{
				title: '加样，提取核酸',
				man: res.two ? res.two.reagentTwo : '',
				time: res.two ? res.timeTwo : '',
				xiaohao: [{
					title: '枪头',
					detail: res.two ? res.two.gunTwo : '',
				}],
				type: res.type,
				status: res.two ? res.two.reagentTwo ? statusChange(equipmentTwos, res.two.equipmentTwo || []) : 2 : 2,
				equipment: res.two ? Compare(equipmentTwos, res.two.equipmentTwo || []) : [],
				index: 1
			},
			{
				title: '扩增体系中加入核酸',
				man: res.two ? res.two.reagentThree : '',
				time: res.two ? res.timeThree : '',
				xiaohao: [{
					title: '枪头',
					detail: res.two ? res.two.gunThree : ''
				}],
				type: res.type,
				status: res.two ? res.two.reagentThree ? statusChange(equipmentTwos, res.two.equipmentThree || []) : 2 : 2,
				equipment: res.two ? Compare(equipmentThrees, res.two.equipmentThree || []) : [],
				index: 2
			},
			{
				title: '上机扩增',
				man: res.three ? res.three.reagentTwo : "",
				time: res.three ? res.timeFour : '',
				xiaohao: [],
				type: res.type,
				status: res.three ? res.three.reagentThree ? statusChange(equipmentTwos, res.three.equipmentTwo || []) : 2 : 2,
				equipment: res.three ? Compare(threeEquipmentTwos, res.three.equipmentTwo || []) : [],
				index: 3
			},
			{
				title: '结果分析',
				man: res.three ? res.three.reagentThree : '',
				time: res.timeFive,
				xiaohao: [],
				type: res.type,
				status: res.three ? res.three.reagentThree ? 1 : 2 : 2,
				index: 4
			}, {
				title: '总检',
				man: res.timeSix ? '总检员' : '',
				time: res.timeSix,
				xiaohao: [],
				type: res.type,
				status: res.timeSix ? 1 : 2,
				index: 5
			
			}
			];
			resolve(arr)
		})
		
		

	}


}

export default step;

	function Compare(Old, New) {
		let arr = JSON.parse((JSON.stringify(Old)));
		const result = arr.map((item) => ({
			title: item,
			status: New.includes(item) ? 1 : 0,
		}));

		return result;
	}

	function statusChange(Old, New) {
		let arr = JSON.parse((JSON.stringify(Old)));
		const result = arr.map((item) => ({
			title: item,
			status: New.includes(item) ? 1 : 0,
		}));
		if (result.filter(item => !item.status).lenght) {
			return 0;
		} else {
			return 1;
		}
	}